home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue63 / Clinic / TestReg.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2000-09-08  |  1.3 KB  |  59 lines

  1. unit TestReg;
  2.  
  3. interface
  4.  
  5. procedure Register;
  6.  
  7. implementation
  8.  
  9. uses
  10.   TestComp, Classes, DsgnIntf, SysUtils;
  11.  
  12. type
  13.   TTestProperty = class(TIntegerProperty)
  14.   public
  15.     function GetAttributes: TPropertyAttributes; override;
  16.     function GetValue: string; override;
  17.     procedure GetValues(Proc: TGetStrProc); override;
  18.     procedure SetValue(const Value: string); override;
  19.   end;
  20.  
  21. function TTestProperty.GetAttributes: TPropertyAttributes;
  22. begin
  23.   //Request list of values
  24.   Result := [paMultiSelect, paValueList, paRevertable];
  25. end;
  26.  
  27. function TTestProperty.GetValue: string;
  28. begin
  29.   //Try and get nice textual name
  30.   if not TestValueToIdent(TTestRange(GetOrdValue), Result) then
  31.     Result := IntToStr(GetOrdValue)
  32. end;
  33.  
  34. procedure TTestProperty.GetValues(Proc: TGetStrProc);
  35. begin
  36.   //Call subrange type helper routine
  37.   GetTestRangeValues(Proc);
  38. end;
  39.  
  40. procedure TTestProperty.SetValue(const Value: string);
  41. var
  42.   NewValue: Longint;
  43. begin
  44.   //Try and translate from textual name
  45.   if IdentToTestValue(Value, NewValue) then
  46.     SetOrdValue(NewValue)
  47.   else
  48.     //Otherwise use numeric value
  49.     inherited SetValue(Value);
  50. end;
  51.  
  52. procedure Register;
  53. begin
  54.   RegisterComponents('Clinic', [TTestComponent]);
  55.   RegisterPropertyEditor(TypeInfo(TTestRange), TTestComponent, 'Test', TTestProperty)
  56. end;
  57.  
  58. end.
  59.